package com.lancoo.answer.ui.child.lookReview;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.lancoo.answer.R;
import com.lancoo.answer.model.AnswerConstant;
import com.lancoo.answer.model.ConstantBean;
import com.lancoo.answer.model.bean.Child;
import com.lancoo.answer.model.bean.ExamViewBean;
import com.lancoo.answer.model.bean.Ques;
import com.lancoo.answer.model.bean.Type;
import com.lancoo.answer.widget.combinationView.AnswerAnalysisView;
import com.lancoo.answer.widget.combinationView.OptionLookingView;
import com.lancoo.answer.widget.combinationView.QueseBodyView;

import java.util.List;

/**
 * Created by pengmi on 2021/12/14 16:10
 * Description:完型填空查看评阅fragment
 */
public class ChildClozeLookReviewFragment extends Fragment {



    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.ev_fragment_quese_cloze, container, false);
    }

    public static Fragment loadChildFragment(int kindIndex, int queseIndex, int smallQueseIndex){
        ChildClozeLookReviewFragment queseFragment=new ChildClozeLookReviewFragment();
        Bundle mBundle=new Bundle();
        mBundle.putInt(AnswerConstant.KEY_TYPEINDEX,kindIndex);
        mBundle.putInt(AnswerConstant.KEY_QUESINDEX,queseIndex);
        mBundle.putInt(AnswerConstant.KEY_CHILDINDEX,smallQueseIndex);
        queseFragment.setArguments(mBundle);
        return queseFragment;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initView(view);
    }

    private void initView(View view){
        if(getArguments()==null){
            return;
        }
        int typeIndex=getArguments().getInt(AnswerConstant.KEY_TYPEINDEX);
        int queseIndex=getArguments().getInt(AnswerConstant.KEY_QUESINDEX);
        int childIndex=getArguments().getInt(AnswerConstant.KEY_CHILDINDEX);
        ExamViewBean constantExamBean = ConstantBean.Companion.getConstantExamBean();
        if(constantExamBean==null){
            return;
        }
        List<Type> typeList = constantExamBean.getTypeList();
        if(typeList==null||typeIndex>=typeList.size()){
            return;
        }
        List<Ques> quesList = typeList.get(typeIndex).getQuesList();
        if(quesList==null||queseIndex>=quesList.size()){
            return;
        }
        Ques ques = quesList.get(queseIndex);
        List<Child> childList = ques.getChildList();
        if(childList==null||childIndex>=childList.size()){
            return;
        }
        Child child = childList.get(childIndex);
        QueseBodyView queseBodyView = view.findViewById(R.id.quese_body_view);
        queseBodyView.initData(child);
        OptionLookingView optionLookingView=view.findViewById(R.id.option_component);
        optionLookingView.setChild(child,ques.getGenreID());
        AnswerAnalysisView answerAnalysisView=view.findViewById(R.id.answer_analysis_view);
        answerAnalysisView.setAnalysis(child.getChildAnalysis());
    }


    public void adjustFontSize(){
        View view = getView();
        if(view ==null){
            return;
        }
        QueseBodyView queseBodyView=view.findViewById(R.id.quese_body_view);
        queseBodyView.adjustFontSize();
        OptionLookingView optionLookingView=view.findViewById(R.id.option_component);
        optionLookingView.adjustFontSize();
    }
}
